<template>
	<view>{{code}}</view>
</template>

<script>
	import utils from '../../common/utils.js'
	export default {
		data() {
			return {
				code: ""
			}
		},
		methods: {
			getAppId() {
				let appid = utils.getQueryString('appid')
				if (!appid) {
					appid = utils.getSession('appid')
				} else {
					utils.setSession('appid', appid)
					config.appid = appid
				}
				return appid
			},

			getLesseeId() {
				let lesseeid = utils.getQueryString("lesseeid")
				if (!lesseeid) {
					lesseeid = utils.getSession('lesseeid')
				} else {
					utils.setSession('lesseeid', lesseeid)
					config.lesseeid = lesseeid
				}
				return lesseeid
			},
		},
		onLoad() {
			this.code = utils.getQueryString("code")
			if (!this.code) {
				let lesseeid = this.getLesseeId()
				let appId = this.getAppId()
				let curWwwPath = encodeURIComponent(window.document.location.href.replace('&code=', ''));
				location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=" +
					curWwwPath + "&response_type=code&scope=snsapi_base&state=" + lesseeid + "#wechat_redirect";
			}

		}
	}
</script>

<style>
</style>
